﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Headquarter.Master" AutoEventWireup="true" CodeBehind="~/Orders.aspx.cs" Inherits="GUI.Headquarter.Orders" EnableEventValidation="false" EnableViewState="false" %>

<%@ Register Assembly="GUI.PaginationControl" Namespace="GUI.PaginationControl" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Encomendas</title>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h1>Encomendas</h1>

    <label for="<%= orderStatusSelect.ClientID %>">Estado da encomenda</label>
    <asp:DropDownList ID="orderStatusSelect" runat="server" AutoPostBack="true">
        <asp:ListItem Value="All">Todos</asp:ListItem>
        <asp:ListItem Value="Ordered">Encomendados</asp:ListItem>
        <asp:ListItem Value="NotOrdered">Não encomendados</asp:ListItem>
    </asp:DropDownList>
    
    

    <% if (productsToOrder != null && productsToOrder.Products != null && productsToOrder.Products.Count > 0){%>
        
        <cc1:PaginationControl 
            ID="PageControlTop" 
            runat="server" 
            PageURI="Orders.aspx" 
            QueryStringParam="page" />


        <div class="products" runat="server">
            
            <h2><%=productsToOrder.Total%> produto(s) encontrado(s)</h2>
            <% for (int i = 0; i < productsToOrder.Products.Count; ++i){ %>    
                <div class="product">
                    <div><span>Codigo </span><%= productsToOrder.Products[i].Code %></div>
                    <div><span>Stock mínimo </span><%= productsToOrder.Products[i].StockMin %></div>
                    <div><span>Stock actual </span><%= productsToOrder.Products[i].Stock %></div>
                    <div><span>Encomendado? </span><%= productsToOrder.Products[i].Ordered ? "Sim" : "Não" %></div>
                    <div id="supplier">
                        Fornecedor
                        <div>
                            <span>Nome</span>
                            <%= productsToOrder.Products[i].Supplier.Name %>
                        </div>
                        <div>
                            <span>Morada</span>
                            <%= productsToOrder.Products[i].Supplier.Address %>
                        </div>
                    </div>
                    <% if (!productsToOrder.Products[i].Ordered){%>
                        <a href="OrderDetails.aspx?code=<%= productsToOrder.Products[i].Code %>">Encomendar</a>
                    <%} %>
                </div>
            <%} %>
        </div>

        <!-- Pages -->
        <cc1:PaginationControl 
            ID="PageControlBottom" 
            runat="server" 
            PageURI="Orders.aspx" 
            QueryStringParam="page" />

    <%}else{ %>
        <div>Não existem produtos disponíveis</div>
    <%} %>

</asp:Content>